

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=dark>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/memory_blog/img/fluid.png">
  <link rel="icon" href="/memory_blog/img/icon/dw.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Memory">
  <meta name="keywords" content="">
  
    <meta name="description" content="🥪 基于自身实践，总结Nginx学习使用过程中的经验">
<meta property="og:type" content="article">
<meta property="og:title" content="Nginx 入门指南：理解、配置和优化">
<meta property="og:url" content="https://test.atomgit.net/memory_blog/2023/06/22/Nginx%20%E5%85%A5%E9%97%A8%E6%8C%87%E5%8D%97%EF%BC%9A%E7%90%86%E8%A7%A3%E3%80%81%E9%85%8D%E7%BD%AE%E5%92%8C%E4%BC%98%E5%8C%96/index.html">
<meta property="og:site_name" content="Memory&#39;s blog">
<meta property="og:description" content="🥪 基于自身实践，总结Nginx学习使用过程中的经验">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://test.atomgit.net/memory_blog/img/artical/town2.jpg">
<meta property="article:published_time" content="2023-06-22T02:04:32.000Z">
<meta property="article:modified_time" content="2024-06-21T04:56:34.000Z">
<meta property="article:author" content="Memory">
<meta property="article:tag" content="经验">
<meta property="article:tag" content="Linux">
<meta property="article:tag" content="Nginx">
<meta property="article:tag" content="Node.js">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://test.atomgit.net/memory_blog/img/artical/town2.jpg">
  
  
  
  <title>Nginx 入门指南：理解、配置和优化 - Memory&#39;s blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/memory_blog/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/memory_blog/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/memory_blog/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"test.atomgit.net","root":"/memory_blog/","version":"1.9.4","typing":{"enable":true,"typeSpeed":100,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":false,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/memory_blog/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/memory_blog/js/utils.js" ></script>
  <script  src="/memory_blog/js/color-schema.js" ></script>
  

  

  

  

  

  

  

  



  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 75vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/memory_blog/">
      <strong>Memory&#39;s blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/memory_blog/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/memory_blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/memory_blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/memory_blog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/memory_blog/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/memory_blog/links/">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/memory_blog/img/newBG/girl.jpg') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Nginx 入门指南：理解、配置和优化"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        Memory
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-06-22 10:04" pubdate>
          2023年6月22日 上午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          17k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          43 分钟
        
      </span>
    

    
    
      
        <span id="leancloud-page-views-container" class="post-meta" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="leancloud-page-views"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar category-bar" style="margin-right: -1rem">
    





<div class="category-list">
  
  
    
    
    
    <div class="category row nomargin-x">
      <a class="category-item 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="Nginx"
        id="heading-62e0b5b350c9e3d2c19aa801d9442ba9" role="tab" data-toggle="collapse" href="#collapse-62e0b5b350c9e3d2c19aa801d9442ba9"
        aria-expanded="true"
      >
        Nginx
        <span class="list-group-count">(1)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-62e0b5b350c9e3d2c19aa801d9442ba9"
           role="tabpanel" aria-labelledby="heading-62e0b5b350c9e3d2c19aa801d9442ba9">
        
        
          
          
  <div class="category-post-list">
    
    
  </div>

          
  
    
    
    
    <div class="category-sub row nomargin-x">
      <a class="category-subitem 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="Linux"
        id="heading-edc9f0a5a5d57797bf68e37364743831" role="tab" data-toggle="collapse" href="#collapse-edc9f0a5a5d57797bf68e37364743831"
        aria-expanded="true"
      >
        Linux
        <span class="list-group-count">(1)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-edc9f0a5a5d57797bf68e37364743831"
           role="tabpanel" aria-labelledby="heading-edc9f0a5a5d57797bf68e37364743831">
        
        
          
          
  <div class="category-post-list">
    
    
  </div>

          
  
    
    
    
    <div class="category-sub row nomargin-x">
      <a class="category-subitem 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="Node.js"
        id="heading-3b2819dd4c24eda2faf2052eef449551" role="tab" data-toggle="collapse" href="#collapse-3b2819dd4c24eda2faf2052eef449551"
        aria-expanded="true"
      >
        Node.js
        <span class="list-group-count">(1)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-3b2819dd4c24eda2faf2052eef449551"
           role="tabpanel" aria-labelledby="heading-3b2819dd4c24eda2faf2052eef449551">
        
        
          
          
  <div class="category-post-list">
    
    
  </div>

          
  
    
    
    
    <div class="category-sub row nomargin-x">
      <a class="category-subitem 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="经验"
        id="heading-32a8e000e928e6dc255876d9fc0178b3" role="tab" data-toggle="collapse" href="#collapse-32a8e000e928e6dc255876d9fc0178b3"
        aria-expanded="true"
      >
        经验
        <span class="list-group-count">(1)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-32a8e000e928e6dc255876d9fc0178b3"
           role="tabpanel" aria-labelledby="heading-32a8e000e928e6dc255876d9fc0178b3">
        
        
          
  <div class="category-post-list">
    
    
      
      
        <a href="/memory_blog/2023/06/22/Nginx%20%E5%85%A5%E9%97%A8%E6%8C%87%E5%8D%97%EF%BC%9A%E7%90%86%E8%A7%A3%E3%80%81%E9%85%8D%E7%BD%AE%E5%92%8C%E4%BC%98%E5%8C%96/" title="Nginx 入门指南：理解、配置和优化"
           class="list-group-item list-group-item-action
           active">
          <span class="category-post">Nginx 入门指南：理解、配置和优化</span>
        </a>
      
    
  </div>

        
      </div>
    </div>
  
        
      </div>
    </div>
  
        
      </div>
    </div>
  
        
      </div>
    </div>
  
</div>


  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Nginx 入门指南：理解、配置和优化</h1>
            
              <p class="note note-success">
                
                  
                    本文最后更新于：17 天前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <h1 id="破冰"><a href="#破冰" class="headerlink" title="破冰"></a>破冰</h1><blockquote>
<p>🥣 推荐阅读：</p>
<ul>
<li><h5 id="67条消息-Nginx-目录结构与配置文件详解-nginx目录-不会调制解调的猫的博客-CSDN博客-（2023-12-15午）"><a href="#67条消息-Nginx-目录结构与配置文件详解-nginx目录-不会调制解调的猫的博客-CSDN博客-（2023-12-15午）" class="headerlink" title="(67条消息) Nginx - 目录结构与配置文件详解_nginx目录_不会调制解调的猫的博客-CSDN博客 （2023/12/15午）"></a><a target="_blank" rel="noopener" href="https://blog.csdn.net/Trollz/article/details/126525238">(67条消息) Nginx - 目录结构与配置文件详解_nginx目录_不会调制解调的猫的博客-CSDN博客</a> （2023/12/15午）</h5></li>
<li><h5 id="Nginx的配置文件详解-KuangStudy-文章"><a href="#Nginx的配置文件详解-KuangStudy-文章" class="headerlink" title="Nginx的配置文件详解-KuangStudy-文章"></a><a target="_blank" rel="noopener" href="https://www.kuangstudy.com/bbs/1619965646882693121">Nginx的配置文件详解-KuangStudy-文章</a></h5></li>
</ul>
</blockquote>
<h2 id="Nginx是什么"><a href="#Nginx是什么" class="headerlink" title="Nginx是什么"></a>Nginx是什么</h2><ul>
<li><h5 id="官⽅解析-："><a href="#官⽅解析-：" class="headerlink" title="官⽅解析 ："></a>官⽅解析 ：</h5></li>
</ul>
<figure class="highlight llvm"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs llvm">Nginx（发⾳为“engine-<span class="hljs-keyword">x</span>”）是⼀个⾼性能的开源 Web 服务器和反向代理服务器，可以处理⼤ 量的并发连接和请求。它使⽤事件驱动的异步架构和多线程设计，可以⾼效地处理并发请求， 同时也⽀持反向代理、负载均衡、动态HTTP缓存、SSL/TLS终⽌、基于模块的扩展等功能。<br></code></pre></td></tr></table></figure>

<ul>
<li><p> Nginx 的应⽤场景⾮常⼴泛，以下是其中的⼏个：</p>
</li>
<li><p> <strong>Web 服务器：</strong>Nginx 可以作为 HTTP 服务器，处理并发的静态请求和动态请求，并且可 以⽀持负载均衡和缓存，为⽹站提供⾼性能和⾼可⽤性。 </p>
</li>
<li><p><strong>反向代理服务器：</strong>Nginx 可以作为反向代理服务器，接收客户端请求并将其转发到后端服 务器，同时也可以⽀持负载均衡和缓存。 </p>
</li>
<li><p><strong>邮件代理服务器：</strong>Nginx 可以作为邮件代理服务器，⽀持 POP3、IMAP 和 SMTP 协议， 并且可以⽀持 SSL/TLS 加密和反垃圾邮件功能。 </p>
</li>
<li><p><strong>流媒体服务器：</strong>Nginx 可以作为流媒体服务器，⽀持 RTMP、HLS 和 DASH 协议，可以 ⽤于实现直播、点播和视频-on-demand（VoD）等场景。 </p>
</li>
<li><h5 id="总之，Nginx-具有⾼性能、可扩展性和可靠性等特点，被⼴泛应⽤于⼤型⽹站、互联⽹公司、-云计算、视频流媒体、游戏等领域"><a href="#总之，Nginx-具有⾼性能、可扩展性和可靠性等特点，被⼴泛应⽤于⼤型⽹站、互联⽹公司、-云计算、视频流媒体、游戏等领域" class="headerlink" title="总之，Nginx 具有⾼性能、可扩展性和可靠性等特点，被⼴泛应⽤于⼤型⽹站、互联⽹公司、 云计算、视频流媒体、游戏等领域"></a>总之，Nginx 具有⾼性能、可扩展性和可靠性等特点，被⼴泛应⽤于⼤型⽹站、互联⽹公司、 云计算、视频流媒体、游戏等领域</h5></li>
</ul>
<h1 id="思维碰撞"><a href="#思维碰撞" class="headerlink" title="思维碰撞"></a>思维碰撞</h1><h2 id="Nginx-部署静态站点（2024最新）"><a href="#Nginx-部署静态站点（2024最新）" class="headerlink" title="Nginx 部署静态站点（2024最新）"></a>Nginx 部署静态站点（2024最新）</h2><blockquote>
<p>2024年6月3日</p>
</blockquote>
<h3 id="Nginx-安装"><a href="#Nginx-安装" class="headerlink" title="Nginx 安装"></a>Nginx 安装</h3><p>这里推荐宝塔面板安装，一条龙完成：</p>
<p>安装宝塔面板：</p>
<p>访问宝塔面板：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">/etc/init.d/bt default	<span class="hljs-comment"># 获取宝塔面板账号密码</span><br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240603091818493.png" alt="image-20240603091818493"></p>
<p>一键编译安装：</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240603091901391.png" alt="image-20240603091901391"></p>
<p>记得查看默认访问端口，宝塔面板安装下的 nginx 默认是 888 端口，云服务器也要开放 888 端口</p>
<p>搞完了直接访问就行。</p>
<h3 id="尝试部署静态页面"><a href="#尝试部署静态页面" class="headerlink" title="尝试部署静态页面"></a>尝试部署静态页面</h3><p><strong>接下来就是四十八小时时间里的踩坑记录</strong>，仅供参照：</p>
<blockquote>
<p>2024年6月1日</p>
</blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/m0_49000161/article/details/132415997">【一篇学会】Nginx静态资源部署保姆级教程_nginx部署静态资源-CSDN博客</a></p>
<p><a target="_blank" rel="noopener" href="https://cloud.tencent.com/developer/article/2363273">Nginx静态资源服务的配置-腾讯云开发者社区-腾讯云 (tencent.com)</a></p>
<figure class="highlight ada"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs ada">MIME 类型<br>MIME（多用途互联网邮件扩展类型）是一种标准化的方式，用于表示文档、文件或字节流的性质和格式。它在IETF RFC <span class="hljs-number">6838</span>中进行了定义和标准化，由互联网号码分配机构（IANA）负责跟踪所有官方MIME类型。MIME类型由两部分组成：类型（<span class="hljs-keyword">type</span>）和子类型（<span class="hljs-keyword">subtype</span>），它们之间用斜杠（/）分隔，不允许空格存在。MIME类型对大小写不敏感，但传统写法都是小写<br></code></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/m0_62231324/article/details/132524647">Nginx配置文件详解-CSDN博客</a></p>
<p><a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1Ku411p73U/?spm_id_from=333.337.search-card.all.click&vd_source=4314e5bd742ea904c9675af8a6b4b07e">8分钟用Nginx搭建一个自己的网站_哔哩哔哩_bilibili</a></p>
<p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/WindSnowLi/p/16998206.html">Linux使用nginx部署静态网页 - WindSnowLi - 博客园 (cnblogs.com)</a></p>
<p><a target="_blank" rel="noopener" href="https://www.jarcheng.top/blog/knowledge/website/#nginx%E9%85%8D%E7%BD%AE">手把手教你搭建静态/博客网站 | 起凡Code闲聊 (jarcheng.top)</a></p>
<p>跟着网上的教程搞了一下午，就是部署不了静态页面，甚至连访问 Nginx 本身都好像有问题，搞不明白，实在是搞不明白。</p>
<p>不管怎么说，今晚我就死磕这个 Nginx 了，多少个晚上都像现在这样把它放过，所以到现在都没有学习完成过 Nginx。</p>
<blockquote>
<p>2024年6月2日</p>
</blockquote>
<p>[root@iZ2ze4yceifsrmdejokfymZ ~]# nginx<br>nginx: [emerg] bind() to 0.0.0.0:7010 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:888 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7071 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7001 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7020 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7010 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:888 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7071 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7001 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7020 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7010 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:888 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7071 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7001 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7020 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7010 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:888 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7071 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7001 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7020 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7010 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:888 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7071 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7001 failed (98: Unknown error)<br>nginx: [emerg] bind() to 0.0.0.0:7020 failed (98: Unknown error)<br>nginx: [emerg] still could not bind()</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240602182928144.png" alt="image-20240602182928144"></p>
<p>[Nginx重启时提示”nginx: <a target="_blank" rel="noopener" href="https://www.8a.hk/index.php/news/content/2898.html">emerg] bind() to 0.0.0.0”解决方法 - 八艾云 (8a.hk)</a></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240602185109255.png" alt="image-20240602185109255"></p>
<p><a target="_blank" rel="noopener" href="https://www.code-nav.cn/post/1652294765397454849#heading-7">极简 Nginx 学习 + 使用，点到为止 - 编程导航文章 (code-nav.cn)</a></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs bash">要查看当前用户是否是管理员（在Unix和Linux系统中通常指的是root用户，或在Windows系统中指的是具有管理员权限的用户），你可以使用不同的方法，具体取决于你使用的操作系统。<br><br>在Unix/Linux系统中：<br><br>查看当前用户名：<br>在终端中输入 <span class="hljs-built_in">whoami</span> 命令。如果输出是 root，那么你就是管理员。<br>查看用户ID：<br>输入 <span class="hljs-built_in">id</span> 命令。如果UID（用户ID）是0，那么你就是root用户。<br>查看/etc/passwd文件（需要root权限）：<br>你可以查看/etc/passwd文件，但通常需要root权限来查看完整的文件内容。使用<span class="hljs-built_in">cat</span> /etc/passwd命令，并查找以root:开头的行。<br>在Windows系统中：<br><br>打开命令提示符：<br>按下Win + R，输入cmd，然后按下Enter键。<br>检查用户账户控制（UAC）提示：<br>当你尝试执行需要管理员权限的任务时，Windows通常会显示一个UAC提示。如果你没有看到这些提示，那么你可能不是以管理员身份登录的。<br>检查用户账户：<br>在“控制面板”中，你可以查看用户账户并检查你的账户是否有管理员权限。<br>使用net user命令（在命令提示符中）：<br>输入net user命令并查看输出。找到你的用户名，并检查它是否列出了管理员组（例如，“Administrators”组）。<br>运行<span class="hljs-built_in">whoami</span> /groups（在命令提示符中）：<br>这个命令将列出你当前用户所属的所有组。如果你看到“S-1-5-32-544”（管理员组的SID），那么你就是管理员。<br>使用PowerShell：<br>在PowerShell中，你可以使用[System.Security.Principal.WindowsIdentity]::GetCurrent().Groups命令来查看当前用户所属的组。然后，你可以检查输出中是否包含管理员组。<br>请注意，成为管理员用户（特别是在Unix/Linux中的root用户）具有极大的权限，可以执行系统范围内的更改。因此，请务必谨慎行事，并在需要时始终考虑使用具有较低权限的用户账户。<br></code></pre></td></tr></table></figure>

<p>netstat -tulnp | grep 7010</p>
<p>我已经尝试了所有方法，查看冲突端口号、关闭防火墙，修改执行用户，更改文件目录权限，根本部署不了静态页面</p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/2301_79099416/article/details/139116845">3分钟搞懂阿里云服务器安装Nginx并配置静态访问页面_阿里云服务器如何安装nginx-CSDN博客</a></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240602213424584.png" alt="image-20240602213424584"></p>
<p>[nginx: <a target="_blank" rel="noopener" href="https://blog.csdn.net/gphjl/article/details/42104639">error] invalid PID number “” in “/usr/local/webserver/nginx/logs/nginx.pid”-CSDN博客</a></p>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs awk">nginx -c <span class="hljs-regexp">/www/</span>server<span class="hljs-regexp">/nginx/</span>conf/nginx.conf<br></code></pre></td></tr></table></figure>

<p>搞不定，一夜回到解放前。</p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/underworld33/article/details/129140664">Nginx部署与静态html_nginx部署html-CSDN博客</a></p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/debimeng/article/details/89005546">【Linux报错】登陆mysql用户报错This account is currently not available._mysql:x:1001:-CSDN博客</a></p>
<blockquote>
<p>2024年6月3日</p>
</blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Keep__Me/article/details/137924903">Linux实现Nginx的安装与部署并实现html静态资源访问_linux nginx html-CSDN博客</a></p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs ini"><span class="hljs-section">[nginx-stable]</span>  <br><span class="hljs-attr">name</span>=nginx stable repo  <br><span class="hljs-attr">baseurl</span>=http://nginx.org/packages/centos/<span class="hljs-number">7</span>/<span class="hljs-variable">$basearch</span>/  <br><span class="hljs-attr">gpgcheck</span>=<span class="hljs-number">1</span>  <br><span class="hljs-attr">enabled</span>=<span class="hljs-number">1</span>  <br><span class="hljs-attr">gpgkey</span>=https://nginx.org/keys/nginx_signing.key  <br><span class="hljs-attr">module_hotfixes</span>=<span class="hljs-literal">true</span>  <br>  <br><span class="hljs-section">[nginx-mainline]</span>  <br><span class="hljs-attr">name</span>=nginx mainline repo  <br><span class="hljs-attr">baseurl</span>=http://nginx.org/packages/mainline/centos/<span class="hljs-number">7</span>/<span class="hljs-variable">$basearch</span>/  <br><span class="hljs-attr">gpgcheck</span>=<span class="hljs-number">1</span>  <br><span class="hljs-attr">enabled</span>=<span class="hljs-number">0</span>  <br><span class="hljs-attr">gpgkey</span>=https://nginx.org/keys/nginx_signing.key  <br><span class="hljs-attr">module_hotfixes</span>=<span class="hljs-literal">true</span><br></code></pre></td></tr></table></figure>

<figure class="highlight ada"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs ada">sudo yum clean <span class="hljs-keyword">all</span>  <br>sudo yum makecache  <br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240603080013103.png" alt="image-20240603080013103"></p>
<figure class="highlight gradle"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs gradle"><span class="hljs-keyword">grep</span> -r <span class="hljs-keyword">exclude</span> <span class="hljs-regexp">/etc/yum</span>.conf <span class="hljs-regexp">/etc/yum</span>.repos.d/<br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240603075634506.png" alt="image-20240603075634506"></p>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs cmake">sudo yum <span class="hljs-keyword">install</span> nginx<br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240603080124927.png" alt="image-20240603080124927"></p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs powershell">systemctl <span class="hljs-built_in">start</span> nginx  <span class="hljs-comment">#启动nginx服务器</span><br><span class="hljs-built_in">ps</span> <span class="hljs-literal">-aux</span> | grep nginx  <span class="hljs-comment">#查看nginx进程</span><br></code></pre></td></tr></table></figure>

<figure class="highlight maxima"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs maxima">systemctl <span class="hljs-built_in">restart</span> nginx<br>systemctl <span class="hljs-built_in">status</span> nginx<br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240603080537255.png" alt="image-20240603080537255"></p>
<figure class="highlight vim"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs vim"><span class="hljs-keyword">find</span> / -name nginx.<span class="hljs-keyword">conf</span><br><br><span class="hljs-keyword">cd</span> ..<br><span class="hljs-keyword">find</span> -name nginx.<span class="hljs-keyword">conf</span><br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240603081030466.png" alt="image-20240603081030466"></p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><code class="hljs nginx"><span class="hljs-section">server</span> &#123;<br>    <span class="hljs-attribute">listen</span>       <span class="hljs-number">80</span>;<br>    <span class="hljs-attribute">server_name</span>  localhost;<br><br>    <span class="hljs-comment">#access_log  /var/log/nginx/host.access.log  main;</span><br><br>    <span class="hljs-attribute">autoindex</span> <span class="hljs-literal">on</span>;<br>    <span class="hljs-section">location</span> / &#123;<br>        <span class="hljs-attribute">root</span>   /usr/share/nginx/html;<br>        <span class="hljs-attribute">index</span>  index.html index.htm;<br>    &#125;<br><br>    <span class="hljs-comment">#error_page  404              /404.html;</span><br><br>    <span class="hljs-comment"># redirect server error pages to the static page /50x.html</span><br>    <span class="hljs-comment">#</span><br>    <span class="hljs-attribute">error_page</span>   <span class="hljs-number">500</span> <span class="hljs-number">502</span> <span class="hljs-number">503</span> <span class="hljs-number">504</span>  /50x.html;<br>    <span class="hljs-section">location</span> = /50x.html &#123;<br>        <span class="hljs-attribute">root</span>   /usr/share/nginx/html;<br>    &#125;<br><br>    <span class="hljs-comment"># proxy the PHP scripts to Apache listening on 127.0.0.1:80</span><br>    <span class="hljs-comment">#</span><br>    <span class="hljs-comment">#location ~ \.php$ &#123;</span><br>    <span class="hljs-comment">#    proxy_pass   http://127.0.0.1;</span><br>    <span class="hljs-comment">#&#125;</span><br><br>    <span class="hljs-comment"># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000</span><br>    <span class="hljs-comment">#</span><br>    <span class="hljs-comment">#location ~ \.php$ &#123;</span><br>    <span class="hljs-comment">#    root           html;</span><br>    <span class="hljs-comment">#    fastcgi_pass   127.0.0.1:9000;</span><br>    <span class="hljs-comment">#    fastcgi_index  index.php;</span><br>    <span class="hljs-comment">#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;</span><br>    <span class="hljs-comment">#    include        fastcgi_params;</span><br>    <span class="hljs-comment">#&#125;</span><br><br>    <span class="hljs-comment"># deny access to .htaccess files, if Apache&#x27;s document root</span><br>    <span class="hljs-comment"># concurs with nginx&#x27;s one</span><br>    <span class="hljs-comment">#</span><br>    <span class="hljs-comment">#location ~ /\.ht &#123;</span><br>    <span class="hljs-comment">#    deny  all;</span><br>    <span class="hljs-comment">#&#125;</span><br>&#125;<br></code></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/nicolelili1/article/details/103381658">nginx服务器搭建好但是浏览器却无法访问原因排查_nginx配置好了 网站还是访问不了-CSDN博客</a></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240603084009334.png" alt="image-20240603084009334"></p>
<p>这几天里报错最恶心的还是这条：</p>
<figure class="highlight vbnet"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs vbnet"><span class="hljs-symbol">nginx:</span> [emerg] bind() <span class="hljs-keyword">to</span> <span class="hljs-number">0.0</span>.<span class="hljs-number">0.0</span>:<span class="hljs-number">7010</span> failed (<span class="hljs-number">98</span>: Unknown <span class="hljs-keyword">error</span>)<br></code></pre></td></tr></table></figure>

<p>最后是在宝塔面板卸载重装以后才解决的，现在也不知道什么原因。</p>
<p><strong>还是很有收获的，学到了许多其他新知识。</strong></p>
<blockquote>
<p>2024年6月4日</p>
</blockquote>
<p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/tt212/p/17684371.html">linux怎么快速卸载并安装node环境 - Jun_ct - 博客园 (cnblogs.com)</a></p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_37450502/article/details/130959110">yum、apt-get、wget的区别_yum wget-CSDN博客</a></p>
<p><a target="_blank" rel="noopener" href="https://cloud.tencent.com/developer/article/2045120">wget、yum、rpm、apt-get区别「建议收藏」-腾讯云开发者社区-腾讯云 (tencent.com)</a></p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/angle_chen123/article/details/120675472">Linux curl命令最全详解-CSDN博客</a></p>
<p>云服务器部署静态博客站点，搞了一上午，代码推送不上去，Nginx 也起不来了。</p>
<p><a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/381967653">运维排查篇 | 访问nginx出现403错误 - 知乎 (zhihu.com)</a></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240604110147986.png" alt="image-20240604110147986"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240604110649330.png" alt="image-20240604110649330"></p>
<p>过了一个小时再尝试，静态代码文件就能推送上去了。杀死已经启动的 Nginx 进程，也能成功启动 Nginx 了。 </p>
<h3 id="问题解决"><a href="#问题解决" class="headerlink" title="问题解决"></a>问题解决</h3><blockquote>
<p>2024年6月3日</p>
</blockquote>
<p>查看本实例的安全组，应用了哪个安全组规则：</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240603090238565.png" alt="image-20240603090238565"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240603090310965.png" alt="image-20240603090310965"></p>
<p>以下这就是应用到的真正的安全组规则（<strong>注意上方地域选择</strong>）：</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240603090138530.png" alt="image-20240603090138530"></p>
<p>这几天以来，一直选错了地域，搞另一个地域下的安全组规则。原来根本就没放开 80、7010、7020 端口：</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240603090604067.png" alt="image-20240603090604067"></p>
<h3 id="重启失败"><a href="#重启失败" class="headerlink" title="重启失败"></a>重启失败</h3><blockquote>
<p>2024年6月4日</p>
</blockquote>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240604105639790.png" alt="image-20240604105639790"></p>
<p>这个报错直接杀死正在运行的 Nginx 进程就可以了。</p>
<h3 id="访问-403-错误"><a href="#访问-403-错误" class="headerlink" title="访问 403 错误"></a>访问 403 错误</h3><blockquote>
<p>2024年6月4日</p>
</blockquote>
<p>🥣 推荐阅读：<a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/381967653">运维排查篇 | 访问nginx出现403错误 - 知乎 (zhihu.com)</a></p>
<h3 id="一条龙"><a href="#一条龙" class="headerlink" title="一条龙"></a>一条龙</h3><blockquote>
<p>2024年6月3日</p>
</blockquote>
<p>🥣 安装 Nginx 并部署静态页面，看这篇博客：<a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/646239152">服务器——Nginx安装及静态配置、部署 - 知乎 (zhihu.com)</a></p>
<p>🍚 解决 Nginx 访问失败问题，看这篇博客：<a target="_blank" rel="noopener" href="https://blog.csdn.net/nicolelili1/article/details/103381658">nginx服务器搭建好但是浏览器却无法访问原因排查_nginx配置好了 网站还是访问不了-CSDN博客</a></p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs routeros">firewall-cmd <span class="hljs-attribute">--zone</span>=public <span class="hljs-attribute">--add-port</span>=8080/tcp --permanent<br></code></pre></td></tr></table></figure>

<figure class="highlight ada"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs ada">firewall-cmd <span class="hljs-comment">--reload</span><br></code></pre></td></tr></table></figure>

<p>使用 Nginx 部署 博客站点，看：</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://www.cnblogs.com/cheyaoyao/p/17836522.html">使用 Hexo 搭建个人博客并部署到云服务器 - Cheyaoyao - 博客园 (cnblogs.com)</a></li>
<li><a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/381967653">运维排查篇 | 访问nginx出现403错误 - 知乎 (zhihu.com)</a></li>
</ul>
<h2 id="CPU-爆满"><a href="#CPU-爆满" class="headerlink" title="CPU 爆满"></a>CPU 爆满</h2><blockquote>
<p>2024年6月21日</p>
</blockquote>
<p>最近一周云服务器 CPU 负载一直很高，经常在80%左右，博客访问都卡的根本打不开。</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240621090813896.png" alt="image-20240621090813896"></p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/shark_chili3007/article/details/104096100">Nginx性能优化_nginx cpu负载高-CSDN博客</a></p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/tiny_du/article/details/119238948">清除nginx连接数TIME_WAIT_nginx连接数满了-CSDN博客</a></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240621082513343.png" alt="image-20240621082513343"></p>
<p><a target="_blank" rel="noopener" href="https://help.aliyun.com/zh/ecs/support/query-and-case-analysis-linux-io-load?spm=a2c6h.13066369.question.5.6ef62f5000GwA0">如何查看Linux系统I/O负载情况_云服务器 ECS(ECS)-阿里云帮助中心 (aliyun.com)</a></p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_30298379/article/details/135491162">云服务器一直提示达到云盘类型的IOPS上限_读写io延迟过长,或达到了该云盘类型的iops上限,导致实例云盘读写受限-CSDN博客</a></p>
<p><a target="_blank" rel="noopener" href="https://www.linuxprobe.com/sdjbmrszwjss.html">swappiness的基本默认设置为60，加上生效这样便完成修改设置 | 《Linux就该这么学》 (linuxprobe.com)</a></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240621090629532.png" alt="image-20240621090629532"></p>
<p>我又重启了服务器实例，试了下上面的方法，看看是否有效。</p>
<p>半个小时过去了，好像问题还真的解决了：</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240621092700202.png" alt="image-20240621092700202"></p>
<blockquote>
<p>2024年7月4日</p>
</blockquote>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240703234449094.png" alt="image-20240703234449094"></p>
<blockquote>
<p>2024年7月8日</p>
</blockquote>
<p>还是老问题：</p>
<p><strong>服务器的 CPU 一直负载很高，监控告警也提示：</strong></p>
<p><strong>当前实例的云盘在2024年7月4日09:43:00出现读写I0延迟过长，或达到了该云盘类型的I0PS上限，导致实例云盘读写受限。</strong></p>
<p><strong>想要远程连接排查问题，Workbench 远程连接服务器又提示已禁用账号密码登录。</strong></p>
<p><strong>改用 VNC 远程连接，进去后没有任何反应，只能胡乱敲字母。</strong></p>
<p><strong>CPU 负载解决不了，部署在服务器上的博客也访问不到。</strong></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240708082555734.png" alt="image-20240708082555734"></p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_35995514/article/details/136542702">【Linux】iftop命令详解-CSDN博客</a></p>
<p><a target="_blank" rel="noopener" href="https://ecs.console.aliyun.com/activeDiagnosisReport/region/cn-beijing?IssueCategoryId=100,104&CurrentCategories=SystemLoadHigh,DiskHighLoad&DiagnosticReportId=dr-2ze9r976kxpb263w76c5">云服务器管理控制台 (aliyun.com)</a></p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_42720845/article/details/138022301">Linux(CentOS)网络流量实时监控（iftop）安装教程——含yum命令安装失败方法_centos iftop-CSDN博客</a></p>
<h2 id="Nodejs-安装"><a href="#Nodejs-安装" class="headerlink" title="Nodejs 安装"></a>Nodejs 安装</h2><blockquote>
<p>2024年6月3日</p>
</blockquote>
<p>linux 安装nodejs yum</p>
<p>在Linux系统中，您可以使用Yum包管理器来安装Node.js。以下是一个基本的步骤和示例代码，用于通过Yum安装Node.js：</p>
<ol>
<li>首先，您需要确保您的系统中已经安装了Node.js的官方Yum仓库。如果尚未安装，您可以通过运行以下命令来添加Node.js的仓库：</li>
</ol>
<figure class="highlight armasm"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs armasm"><span class="hljs-symbol">curl</span> -<span class="hljs-built_in">sL</span> https:<span class="hljs-comment">//rpm.nodesource.com/setup_14.x | sudo bash -</span><br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240604085311073.png" alt="image-20240604085311073"></p>
<p>这个命令会将Node.js 14.x的仓库添加到您的系统中。如果您想安装其他版本的Node.js，只需将<code>setup_14.x</code>中的数字更改为所需的Node.js版本即可。</p>
<ol>
<li>接下来，您可以使用Yum安装Node.js：</li>
</ol>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs cmake">sudo yum <span class="hljs-keyword">install</span> -y nodejs<br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240604085407699.png" alt="image-20240604085407699"></p>
<p>这个命令会从刚才添加的Node.js仓库中安装Node.js。</p>
<ol>
<li>安装完成后，您可以检查Node.js的版本确保安装成功：</li>
</ol>
<figure class="highlight crmsh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs crmsh"><span class="hljs-keyword">node</span> <span class="hljs-title">--version</span><br></code></pre></td></tr></table></figure>

<p>请注意，上述命令中的URL和版本号可能会随着Node.js版本更新而变化，请参照Node.js官方文档或者NodeSource提供的最新安装脚本。</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240604090040331.png" alt="image-20240604090040331"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240604105048890.png" alt="image-20240604105048890"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240604105149238.png" alt="image-20240604105149238"></p>
<h2 id="部署"><a href="#部署" class="headerlink" title="部署"></a>部署</h2><p>看过了上面的一条龙 Nginx 部署静态站点服务后，基本上搞定了所有 Nginx 问题</p>
<h2 id="Nginx-安装-1"><a href="#Nginx-安装-1" class="headerlink" title="Nginx 安装"></a>Nginx 安装</h2><blockquote>
<p>2024年6月9日</p>
</blockquote>
<p>注意，这里还是上面提到的那篇博文内容，感觉还是把详细步骤记录下来比较好：</p>
<h3 id="安装Nginx步骤"><a href="#安装Nginx步骤" class="headerlink" title="安装Nginx步骤"></a><strong>安装Nginx步骤</strong></h3><p>有两种安装Nginx方法：</p>
<p>一种是快速安装，直接执行下面代码即可：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">yum install nginx<br></code></pre></td></tr></table></figure>

<p>另一种是设置nginx.repo源安装，我们推荐使用设置nginx.repo源安装，具体步骤如下所示：</p>
<h3 id="安装yum-utils"><a href="#安装yum-utils" class="headerlink" title="安装yum-utils"></a><strong>安装yum-utils</strong></h3><p>在安装之前，首先要安装yum-utils，执行如下代码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">yum install yum-utils<br></code></pre></td></tr></table></figure>

<h3 id="配置nginx-repo源"><a href="#配置nginx-repo源" class="headerlink" title="配置nginx.repo源"></a><strong>配置nginx.repo源</strong></h3><p>首先在/etc/yum.repos.d目录下创建nginx.repo文件，执行如下代码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-built_in">touch</span> /etc/yum.repos.d/nginx.repo<br></code></pre></td></tr></table></figure>

<p>在nginx.repo文件中写入以下代码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs bash">vim /etc/yum.repos.d/nginx.repo  <span class="hljs-comment">#进入nginx.repo文件</span><br><span class="hljs-comment"># 写入以下代码：</span><br>[nginx-stable]<br>name=nginx stable repo<br>baseurl=http://nginx.org/packages/centos/<span class="hljs-variable">$releasever</span>/<span class="hljs-variable">$basearch</span>/<br>gpgcheck=1<br>enabled=1<br>gpgkey=https://nginx.org/keys/nginx_signing.key<br>module_hotfixes=<span class="hljs-literal">true</span><br><br>[nginx-mainline]<br>name=nginx mainline repo<br>baseurl=http://nginx.org/packages/mainline/centos/<span class="hljs-variable">$releasever</span>/<span class="hljs-variable">$basearch</span>/<br>gpgcheck=1<br>enabled=0<br>gpgkey=https://nginx.org/keys/nginx_signing.key<br>module_hotfixes=<span class="hljs-literal">true</span><br></code></pre></td></tr></table></figure>

<p>写入文件后，保存并退出，执行如下代码查看是否加载了Nginx安装源：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">yum repolist<br></code></pre></td></tr></table></figure>

<p><img src="https://pic1.zhimg.com/80/v2-06481da518e45426abb4da78d3f926d0_1440w.webp" alt="img"></p>
<h3 id="安装nginx"><a href="#安装nginx" class="headerlink" title="安装nginx"></a><strong>安装nginx</strong></h3><p>安装nginx执行如下代码即可安装：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">yum install nginx<br></code></pre></td></tr></table></figure>

<h3 id="系统启动nginx服务器"><a href="#系统启动nginx服务器" class="headerlink" title="系统启动nginx服务器"></a><strong>系统启动nginx服务器</strong></h3><p>在系统管理中，我们可以执行如下代码启动nginx服务器：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs bash">systemctl start nginx  <span class="hljs-comment">#启动nginx服务器</span><br>ps -aux | grep nginx  <span class="hljs-comment">#查看nginx进程</span><br></code></pre></td></tr></table></figure>

<p>如下图所示：</p>
<p><img src="https://pic2.zhimg.com/80/v2-358bcd2ab2eb80b2b6951522fb45d879_1440w.webp" alt="img"></p>
<p>这样就启动了nginx服务器，我们进入浏览器并输入公网id即可看到如下页面：</p>
<p><img src="https://pic4.zhimg.com/80/v2-20b977106f5a862933564a6756fed127_1440w.webp" alt="img"></p>
<p>假如没能成功显示该页面，则需要在云服务器开放80端口。</p>
<h3 id="nginx-conf配置"><a href="#nginx-conf配置" class="headerlink" title="nginx.conf配置"></a><strong>nginx.conf配置</strong></h3><p>为什么输入本机的IP地址就会显示上面的网页呢，带着疑问，我们来看看Nginx的配置文件，nginx默认的配置文件nginx.conf的目录为：/etc/nginx/nginx.conf，也可以执行如下代码找出nginx.conf的位置：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">find -name nginx.conf<br></code></pre></td></tr></table></figure>

<p>如下图所示：</p>
<p><img src="https://pic4.zhimg.com/80/v2-affa2676eaaca61e117841043eb183fb_1440w.webp" alt="img"></p>
<p>找到nginx.conf配置文件路径后，进入nginx.conf配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><code class="hljs bash">vim /etc/nginx/nginx.conf<br>user  nginx;<br>worker_processes  auto;<br><br>error_log  /var/log/nginx/error.log notice;<br>pid        /var/run/nginx.pid;<br><br><br>events &#123;<br>    worker_connections  1024;<br>&#125;<br><br><br>http &#123;<br>    include       /etc/nginx/mime.types;<br>    default_type  application/octet-stream;<br><br>    log_format  main  <span class="hljs-string">&#x27;$remote_addr - $remote_user [$time_local] &quot;$request&quot; &#x27;</span><br>                      <span class="hljs-string">&#x27;$status $body_bytes_sent &quot;$http_referer&quot; &#x27;</span><br>                      <span class="hljs-string">&#x27;&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;&#x27;</span>;<br><br>    access_log  /var/log/nginx/access.log  main;<br><br>    sendfile        on;<br>    <span class="hljs-comment">#tcp_nopush     on;</span><br><br>    keepalive_timeout  65;<br><br>    <span class="hljs-comment">#gzip  on;</span><br><br>    include /etc/nginx/conf.d/*.conf;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>其内容如下所示：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><code class="hljs bash">user  nginx;     <span class="hljs-comment">#用户名</span><br>worker_processes  auto;    <span class="hljs-comment">#工作进程数为自动增加</span><br><br>error_log  /var/log/nginx/error.log notice;  <span class="hljs-comment">#错误日志文件</span><br>pid        /var/run/nginx.pid;    <span class="hljs-comment">#进程文件</span><br><br><br>events &#123;<br>    worker_connections  1024;  <span class="hljs-comment">#允许同时连接的连接数</span><br>&#125;<br><br><br>http &#123;<br>    include       /etc/nginx/mime.types;  <span class="hljs-comment">#http请求类型文件</span><br>    default_type  application/octet-stream;  <span class="hljs-comment">#默认为application的http请求</span><br><br>    log_format  main  <span class="hljs-string">&#x27;$remote_addr - $remote_user [$time_local] &quot;$request&quot; &#x27;</span><br>                      <span class="hljs-string">&#x27;$status $body_bytes_sent &quot;$http_referer&quot; &#x27;</span><br>                      <span class="hljs-string">&#x27;&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;&#x27;</span>;  <span class="hljs-comment">#日志格式</span><br><br>    access_log  /var/log/nginx/access.log  main;    <span class="hljs-comment">#日志目录</span><br><br>    sendfile        on;<br>    <span class="hljs-comment">#tcp_nopush     on;</span><br><br>    keepalive_timeout  65;      <span class="hljs-comment">#连接超时时间</span><br><br>    <span class="hljs-comment">#gzip  on;        #压缩格式</span><br> <br>    include /etc/nginx/conf.d/*.conf;  <span class="hljs-comment">#辅助配置文件 </span><br>&#125;<br></code></pre></td></tr></table></figure>

<p>我们在nginx.conf配置文件中没有找到呈现刚才网页直接相关的代码，只有一个辅助配置文件，那么我们执行如下代码进入复制配置文件目录：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-built_in">cd</span> /etc/nginx/conf.d<br><span class="hljs-built_in">ls</span><br></code></pre></td></tr></table></figure>

<p>发现只有一个名为default.conf的配置文件，执行如下代码进入default.conf辅助配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">vim /etc/nginx/conf.d/*.conf<br></code></pre></td></tr></table></figure>

<p>其内容如下所示：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><code class="hljs bash">server &#123;<br>    listen       80;    <span class="hljs-comment">#服务器端口号</span><br>    server_name  localhost;   <span class="hljs-comment">#服务器名</span><br><br>    <span class="hljs-comment">#access_log  /var/log/nginx/host.access.log  main;</span><br><br>    location / &#123;         <span class="hljs-comment">#项目网址http:ip地址/</span><br>        root   /usr/share/nginx/html;   <span class="hljs-comment">#项目路径</span><br>        index  index.html index.htm;   <span class="hljs-comment">#http文件</span><br>    &#125;<br><br>    <span class="hljs-comment">#error_page  404              /404.html;</span><br><br>    <span class="hljs-comment"># redirect server error pages to the static page /50x.html</span><br>    <span class="hljs-comment">#</span><br>    error_page   500 502 503 504  /50x.html;  <span class="hljs-comment">#访问出错500,502,503,504时呈现50x.html网页</span><br>    location = /50x.html &#123;<br>        root   /usr/share/nginx/html;<br>    &#125;<br><br>    <span class="hljs-comment"># proxy the PHP scripts to Apache listening on 127.0.0.1:80</span><br>    <span class="hljs-comment">#</span><br>    <span class="hljs-comment">#location ~ \.php$ &#123;</span><br>    <span class="hljs-comment">#    proxy_pass   http://127.0.0.1;</span><br>    <span class="hljs-comment">#&#125;</span><br><br>    <span class="hljs-comment"># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000</span><br>    <span class="hljs-comment">#</span><br>    <span class="hljs-comment">#location ~ \.php$ &#123;</span><br>    <span class="hljs-comment">#    root           html;</span><br>    <span class="hljs-comment">#    fastcgi_pass   127.0.0.1:9000;</span><br>    <span class="hljs-comment">#    fastcgi_index  index.php;</span><br>    <span class="hljs-comment">#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;</span><br>    <span class="hljs-comment">#    include        fastcgi_params;</span><br>    <span class="hljs-comment">#&#125;</span><br><br>    <span class="hljs-comment"># deny access to .htaccess files, if Apache&#x27;s document root</span><br>    <span class="hljs-comment"># concurs with nginx&#x27;s one</span><br>    <span class="hljs-comment">#</span><br>    <span class="hljs-comment">#location ~ /\.ht &#123;</span><br>    <span class="hljs-comment">#    deny  all;</span><br>    <span class="hljs-comment">#&#125;</span><br>&#125;<br></code></pre></td></tr></table></figure>

<p>在辅助配置文件中，我们找到了网页项目文件相关的代码，我们进入/usr/share/nginx/html项目路径，执行如下代码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">vim /usr/share/nginx/html/index.html <br></code></pre></td></tr></table></figure>

<p>打开index.html，发现其内容正是我们刚才公网id访问浏览器显示的内容。</p>
<p>也就是说，只要我们修改default.conf配置文件中的项目路径改为我们项目的路径，即可把我们的项目放在服务器上面了，但是一般情况下，我们都不会去修改nginx原来的default.conf配置文件，一般会通过使用自定义的配置文件来启动nginx服务。</p>
<h3 id="关闭nginx服务器"><a href="#关闭nginx服务器" class="headerlink" title="关闭nginx服务器"></a><strong>关闭nginx服务器</strong></h3><p>当我们使用系统管理来启动nginx服务器时，需要系统管理来关闭nginx服务器，执行如下代码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">systemctl stop nginx<br></code></pre></td></tr></table></figure>

<p>可以根据需求执行如下代码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment">#通过系统管理nginx服务</span><br>systemctl <span class="hljs-built_in">enable</span> nginx   <span class="hljs-comment">#设置nginx为开机启动</span><br>systemctl <span class="hljs-built_in">disable</span> nginx  <span class="hljs-comment">#禁止开机启动</span><br>systemctl status nginx   <span class="hljs-comment">#查看nginx状态</span><br>systemctl start nginx   <span class="hljs-comment">#启动nginx服务</span><br>systemctl stop nginx <span class="hljs-comment">#关闭nginx服务</span><br></code></pre></td></tr></table></figure>

<h3 id="配置文件启动nginx服务"><a href="#配置文件启动nginx服务" class="headerlink" title="配置文件启动nginx服务"></a><strong>配置文件启动nginx服务</strong></h3><p>在使用系统管理启动nginx服务时，浏览器访问自身的IP地址呈现的是一个欢迎使用nginx服务的网页，要想浏览器访问自身的IP地址呈现的是其他网页时，需要修改其辅助配置文件default.conf，但一般情况下，我们不会去修改nginx原来的default.conf配置文件，那么怎么启动nginx服务器让浏览器访问自身IP地址呈现其他网页呢？</p>
<p>这时我们可以自己编写一个nginx配置文件mynginx.conf（配置文件名可以随意），执行以下代码来启动nginx服务：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">nginx -c 配置文件路径<br></code></pre></td></tr></table></figure>

<h3 id="配置文件编写"><a href="#配置文件编写" class="headerlink" title="配置文件编写"></a><strong>配置文件编写</strong></h3><p>那么问题来了，如何编写nginx配置文件呢？首先系统管理启动nginx服务涉及了两个配置文件——nginx.conf和default.conf，其中控制网页内容的呈现相关的是default.conf配置文件，而nginx.conf是一些日志、错误等一些文件配置，所以我们只需要把nginx.conf配置文件和default.conf配置文件的内容复制在自己编写的mynginx.conf配置文件即可，复制代码后，我们通过增删改查，最终得出以下代码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><code class="hljs bash">user  root;       <span class="hljs-comment">#将nginx.conf的nginx改为root</span><br>worker_processes  auto;<br><br>error_log  /var/log/nginx/error.log notice;<br>pid        /var/run/nginx.pid;<br><br>events &#123;<br>    worker_connections  1024;<br>&#125;<br><br>http &#123;<br>    include       /etc/nginx/mime.types;<br>    default_type  application/octet-stream;<br><br>    log_format  main  <span class="hljs-string">&#x27;$remote_addr - $remote_user [$time_local] &quot;$request&quot; &#x27;</span><br>                      <span class="hljs-string">&#x27;$status $body_bytes_sent &quot;$http_referer&quot; &#x27;</span><br>                      <span class="hljs-string">&#x27;&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;&#x27;</span>;<br><br>    access_log  /var/log/nginx/access.log  main;<br><br>    sendfile        on;<br>    <span class="hljs-comment">#tcp_nopush     on;</span><br><br>    keepalive_timeout  65;<br><br>    <span class="hljs-comment">#gzip  on;</span><br><br>    server &#123;        <span class="hljs-comment">#default.conf代码复制在nginx.conf配置文件的http里面，并将注释的代码删除</span><br>    listen       6789;<br>    server_name  localhost;<br><br>    location / &#123;<br>        root   /tmp/test/templates;    <span class="hljs-comment">#修改为你项目的路径</span><br>        index  Hello.html Hello.htm;    <span class="hljs-comment">#修改为你的首页网页</span><br>    &#125;<br>&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>修改的地方我们已经在代码中注释了，好了，通过简单的修改复制的代码，我们成功编写了自己的nginx配置文件mynginx.conf，我们将配置文件放在Flask程序根目录中。</p>
<p>Flask程序如下所示：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs bash">from flask import Flask, render_template<br>app = Flask(__name__)<br>app.config[<span class="hljs-string">&#x27;DEBUG&#x27;</span>]=True<br>app.config[<span class="hljs-string">&#x27;ENV&#x27;</span>]=<span class="hljs-string">&#x27;development&#x27;</span><br><br>@app.route(<span class="hljs-string">&#x27;/&#x27;</span>)<br>def hello_world():<br>    <span class="hljs-built_in">return</span> render_template(<span class="hljs-string">&#x27;Hello.html&#x27;</span>)<br><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&#x27;__main__&#x27;</span>:<br>    app.run()<br></code></pre></td></tr></table></figure>

<h3 id="启动nginx服务"><a href="#启动nginx服务" class="headerlink" title="启动nginx服务"></a><strong>启动nginx服务</strong></h3><p>好了，配置文件已经写好了，执行如下代码启动nginx服务：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs bash">nginx -c /root/demo/myflask/mynginx.conf   <span class="hljs-comment">#启动nginx服务</span><br>ps -aux | grep nginx       <span class="hljs-comment">#查看nginx进程</span><br></code></pre></td></tr></table></figure>

<p>这样我们就启动了自己编写的nginx配置文件，如下图所示：</p>
<p><img src="https://pic4.zhimg.com/80/v2-d9ad1e54609d48866fae8b1c7ff5d3cf_1440w.webp" alt="img"></p>
<p>浏览器访问<a href="https://link.zhihu.com/?target=http://ip">http://ip</a>:port，这里我们设置的端口号为6789，如下图所示：</p>
<p><img src="https://pic2.zhimg.com/80/v2-90996ce157d005a672765faa64cc4291_1440w.webp" alt="img"></p>
<h3 id="关闭nginx服务"><a href="#关闭nginx服务" class="headerlink" title="关闭nginx服务"></a><strong>关闭nginx服务</strong></h3><p>通过配置文件启动nginx服务，需要执行如下代码关闭nginx服务：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs bash">nginx -s quit  <span class="hljs-comment">#正常关闭</span><br>nginx -s stop  <span class="hljs-comment">#快速关闭</span><br>nginx -s reload   <span class="hljs-comment">#重新加载配置</span><br></code></pre></td></tr></table></figure>

<p>好了，服务器——Nginx安装及Nginx静态配置、部署就讲到这里了。</p>
<h2 id="Nginx简介和安装"><a href="#Nginx简介和安装" class="headerlink" title="Nginx简介和安装"></a>Nginx简介和安装</h2><ul>
<li><h5 id="了解-Nginx：功能、优势和应用场景"><a href="#了解-Nginx：功能、优势和应用场景" class="headerlink" title="了解 Nginx：功能、优势和应用场景"></a>了解 Nginx：功能、优势和应用场景</h5></li>
</ul>
<h3 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h3><ul>
<li><h5 id="这篇关于Nginx的介绍是我看过最详细的了：Nginx-学习-KuangStudy-文章"><a href="#这篇关于Nginx的介绍是我看过最详细的了：Nginx-学习-KuangStudy-文章" class="headerlink" title="这篇关于Nginx的介绍是我看过最详细的了：Nginx 学习-KuangStudy-文章"></a>这篇关于Nginx的介绍是我看过最详细的了：<a target="_blank" rel="noopener" href="https://www.kuangstudy.com/bbs/1483987971375263745">Nginx 学习-KuangStudy-文章</a></h5></li>
<li><h5 id="这里我就不详细展开说了，网上的资料对Nginx都有着详尽的介绍，我仅依照自己的理解，给出我对Nginx的认识："><a href="#这里我就不详细展开说了，网上的资料对Nginx都有着详尽的介绍，我仅依照自己的理解，给出我对Nginx的认识：" class="headerlink" title="这里我就不详细展开说了，网上的资料对Nginx都有着详尽的介绍，我仅依照自己的理解，给出我对Nginx的认识："></a>这里我就不详细展开说了，网上的资料对Nginx都有着详尽的介绍，我仅依照自己的理解，给出我对Nginx的认识：</h5></li>
<li><h5 id="Nginx是一个高性能的HTTP和反向代理web服务器，它的特点是负载均衡、反向代理"><a href="#Nginx是一个高性能的HTTP和反向代理web服务器，它的特点是负载均衡、反向代理" class="headerlink" title="Nginx是一个高性能的HTTP和反向代理web服务器，它的特点是负载均衡、反向代理"></a>Nginx是一个高性能的HTTP和反向代理web服务器，它的特点是负载均衡、反向代理</h5></li>
</ul>
<h3 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h3><h4 id="windows安装"><a href="#windows安装" class="headerlink" title="windows安装"></a>windows安装</h4><ul>
<li><h5 id="Nginx官网下载：nginx-download"><a href="#Nginx官网下载：nginx-download" class="headerlink" title="Nginx官网下载：nginx: download"></a>Nginx官网下载：<a target="_blank" rel="noopener" href="http://nginx.org/en/download.html">nginx: download</a></h5></li>
<li><h5 id="只需在官网下载安装包，在本地解压即可"><a href="#只需在官网下载安装包，在本地解压即可" class="headerlink" title="只需在官网下载安装包，在本地解压即可"></a>只需在官网下载安装包，在本地解压即可</h5></li>
</ul>
<h4 id="本地Linux原始安装"><a href="#本地Linux原始安装" class="headerlink" title="本地Linux原始安装"></a>本地Linux原始安装</h4><ul>
<li><h5 id="手动安装并手动配置是很繁琐的，不过操作一遍确实很能巩固Linux命令，这里给出详细的安装教程："><a href="#手动安装并手动配置是很繁琐的，不过操作一遍确实很能巩固Linux命令，这里给出详细的安装教程：" class="headerlink" title="手动安装并手动配置是很繁琐的，不过操作一遍确实很能巩固Linux命令，这里给出详细的安装教程："></a>手动安装并手动配置是很繁琐的，不过操作一遍确实很能巩固Linux命令，这里给出详细的安装教程：</h5></li>
<li><h5 id="Nginx官网下载：nginx-download-1"><a href="#Nginx官网下载：nginx-download-1" class="headerlink" title="Nginx官网下载：nginx: download"></a>Nginx官网下载：<a target="_blank" rel="noopener" href="http://nginx.org/en/download.html">nginx: download</a></h5></li>
<li><h5 id="教程一：Nginx安装下载-KuangStudy-文章"><a href="#教程一：Nginx安装下载-KuangStudy-文章" class="headerlink" title="教程一：Nginx安装下载-KuangStudy-文章"></a>教程一：<a target="_blank" rel="noopener" href="https://www.kuangstudy.com/bbs/1511610238649233410">Nginx安装下载-KuangStudy-文章</a></h5></li>
<li><h5 id="教程二：-67条消息-Nginx安装及其常用命令（实操版）-nginx安装命令-叫我-默语的博客-CSDN博客"><a href="#教程二：-67条消息-Nginx安装及其常用命令（实操版）-nginx安装命令-叫我-默语的博客-CSDN博客" class="headerlink" title="教程二：(67条消息) Nginx安装及其常用命令（实操版）_nginx安装命令_叫我 默语的博客-CSDN博客"></a>教程二：<a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_42055933/article/details/130734077">(67条消息) Nginx安装及其常用命令（实操版）_nginx安装命令_叫我 默语的博客-CSDN博客</a></h5></li>
<li><h5 id="教程三：-67条消息-yum安装nginx-yum-安装nginx-q495673918的博客-CSDN博客"><a href="#教程三：-67条消息-yum安装nginx-yum-安装nginx-q495673918的博客-CSDN博客" class="headerlink" title="教程三：(67条消息) yum安装nginx_yum 安装nginx_q495673918的博客-CSDN博客"></a>教程三：<a target="_blank" rel="noopener" href="https://blog.csdn.net/q495673918/article/details/124477891">(67条消息) yum安装nginx_yum 安装nginx_q495673918的博客-CSDN博客</a></h5></li>
<li><h5 id="将来有空的话，我会补充这里的手动安装实操流程（宝塔一键安装真的太便捷了）"><a href="#将来有空的话，我会补充这里的手动安装实操流程（宝塔一键安装真的太便捷了）" class="headerlink" title="将来有空的话，我会补充这里的手动安装实操流程（宝塔一键安装真的太便捷了）"></a>将来有空的话，我会补充这里的手动安装实操流程（宝塔一键安装真的太便捷了）</h5></li>
</ul>
<h4 id="宝塔Linux一键安装"><a href="#宝塔Linux一键安装" class="headerlink" title="宝塔Linux一键安装"></a>宝塔Linux一键安装</h4><ul>
<li><h5 id="不论是云服务器还是本地服务器，宝塔Linux都是一键安装的，省去了大部分繁琐的配置"><a href="#不论是云服务器还是本地服务器，宝塔Linux都是一键安装的，省去了大部分繁琐的配置" class="headerlink" title="不论是云服务器还是本地服务器，宝塔Linux都是一键安装的，省去了大部分繁琐的配置"></a>不论是云服务器还是本地服务器，宝塔Linux都是一键安装的，省去了大部分繁琐的配置</h5></li>
<li><h5 id="你可以在登录宝塔面板之后，在软件商店里下载安装："><a href="#你可以在登录宝塔面板之后，在软件商店里下载安装：" class="headerlink" title="你可以在登录宝塔面板之后，在软件商店里下载安装："></a>你可以在登录宝塔面板之后，在软件商店里下载安装：</h5></li>
</ul>
<img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230622143528026.png" alt="image-20230622143528026" style="zoom:150%;" />

<ul>
<li><h5 id="也可以在终端里，像本地Linux服务器一样，使用命令安装配置Nginx"><a href="#也可以在终端里，像本地Linux服务器一样，使用命令安装配置Nginx" class="headerlink" title="也可以在终端里，像本地Linux服务器一样，使用命令安装配置Nginx"></a>也可以在终端里，像本地Linux服务器一样，使用命令安装配置Nginx</h5></li>
</ul>
<h2 id="服务启停"><a href="#服务启停" class="headerlink" title="服务启停"></a>服务启停</h2><ul>
<li><h5 id="学会安装、启动和停止-Nginx-服务"><a href="#学会安装、启动和停止-Nginx-服务" class="headerlink" title="学会安装、启动和停止 Nginx 服务"></a>学会安装、启动和停止 Nginx 服务</h5></li>
<li><h5 id="这里补充下Nginx常用命令："><a href="#这里补充下Nginx常用命令：" class="headerlink" title="这里补充下Nginx常用命令："></a>这里补充下Nginx常用命令：</h5></li>
</ul>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs nginx"><span class="hljs-attribute">nginx</span> 					<span class="hljs-comment"># 启动Nginx </span><br></code></pre></td></tr></table></figure>

<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs nginx"><span class="hljs-attribute">nginx</span> -c filename  		<span class="hljs-comment"># 指定配置⽂件 </span><br></code></pre></td></tr></table></figure>

<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs nginx"><span class="hljs-attribute">nginx</span> -V 				<span class="hljs-comment"># 查看Nginx的版本和编译参数等信息 </span><br></code></pre></td></tr></table></figure>

<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs nginx"><span class="hljs-attribute">nginx</span> -t 				<span class="hljs-comment"># 检查配置⽂件是否正确，也可⽤来定位配置⽂件的位置 </span><br></code></pre></td></tr></table></figure>

<figure class="highlight jboss-cli"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs jboss-cli">nginx -s <span class="hljs-keyword">quit</span> 			<span class="hljs-comment"># 优雅停⽌Nginx</span><br></code></pre></td></tr></table></figure>

<figure class="highlight crmsh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs crmsh">nginx -s <span class="hljs-literal">stop</span> 			<span class="hljs-comment"># 快速停⽌Nginx</span><br></code></pre></td></tr></table></figure>

<figure class="highlight jboss-cli"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs jboss-cli">nginx -s <span class="hljs-keyword">reload</span> 		<span class="hljs-comment"># 重新加载配置⽂件 </span><br></code></pre></td></tr></table></figure>

<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs nginx"><span class="hljs-attribute">nginx</span> -s reopen 		<span class="hljs-comment"># 重新打开⽇志⽂件</span><br></code></pre></td></tr></table></figure>

<h2 id="配置文件"><a href="#配置文件" class="headerlink" title="配置文件"></a>配置文件</h2><blockquote>
<p>🔥 推荐阅读：</p>
</blockquote>
<ul>
<li><h5 id="深入理解-Nginx-配置文件：语法、块和常用指令"><a href="#深入理解-Nginx-配置文件：语法、块和常用指令" class="headerlink" title="深入理解 Nginx 配置文件：语法、块和常用指令"></a>深入理解 Nginx 配置文件：语法、块和常用指令</h5></li>
<li><h5 id="介绍下Nginx目录结构和配置文件的内容："><a href="#介绍下Nginx目录结构和配置文件的内容：" class="headerlink" title="介绍下Nginx目录结构和配置文件的内容："></a>介绍下Nginx目录结构和配置文件的内容：</h5></li>
<li><h5 id="67条消息-Nginx-目录结构与配置文件详解-nginx目录-不会调制解调的猫的博客-CSDN博客"><a href="#67条消息-Nginx-目录结构与配置文件详解-nginx目录-不会调制解调的猫的博客-CSDN博客" class="headerlink" title="(67条消息) Nginx - 目录结构与配置文件详解_nginx目录_不会调制解调的猫的博客-CSDN博客"></a><a target="_blank" rel="noopener" href="https://blog.csdn.net/Trollz/article/details/126525238">(67条消息) Nginx - 目录结构与配置文件详解_nginx目录_不会调制解调的猫的博客-CSDN博客</a></h5></li>
<li><h5 id="Nginx的配置文件详解-KuangStudy-文章-1"><a href="#Nginx的配置文件详解-KuangStudy-文章-1" class="headerlink" title="Nginx的配置文件详解-KuangStudy-文章"></a><a target="_blank" rel="noopener" href="https://www.kuangstudy.com/bbs/1619965646882693121">Nginx的配置文件详解-KuangStudy-文章</a></h5></li>
</ul>
<h2 id="反向代理和负载均衡"><a href="#反向代理和负载均衡" class="headerlink" title="反向代理和负载均衡"></a>反向代理和负载均衡</h2><ul>
<li><h5 id="Nginx-反向代理和负载均衡：有效分发流量"><a href="#Nginx-反向代理和负载均衡：有效分发流量" class="headerlink" title="Nginx 反向代理和负载均衡：有效分发流量"></a>Nginx 反向代理和负载均衡：有效分发流量</h5></li>
<li><h5 id="我们在本地的4000、5173、8080三个端口开启静态站点服务："><a href="#我们在本地的4000、5173、8080三个端口开启静态站点服务：" class="headerlink" title="我们在本地的4000、5173、8080三个端口开启静态站点服务："></a>我们在本地的4000、5173、8080三个端口开启静态站点服务：</h5></li>
</ul>
<p><img src="C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20230708095447602.png" alt="image-20230708095447602"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230708095520028.png" alt="image-20230708095520028"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230708095552638.png" alt="image-20230708095552638"></p>
<ul>
<li><h5 id="在nginx-conf文件下，分别开放8887、8888、8889端口，反向代理三个静态站点服务"><a href="#在nginx-conf文件下，分别开放8887、8888、8889端口，反向代理三个静态站点服务" class="headerlink" title="在nginx.conf文件下，分别开放8887、8888、8889端口，反向代理三个静态站点服务"></a>在nginx.conf文件下，分别开放8887、8888、8889端口，反向代理三个静态站点服务</h5></li>
<li><h5 id="详细配置如下："><a href="#详细配置如下：" class="headerlink" title="详细配置如下："></a>详细配置如下：</h5></li>
</ul>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><code class="hljs nginx"><span class="hljs-section">http</span> &#123;<br>    <span class="hljs-attribute">include</span>       mime.types;<br>    <span class="hljs-attribute">default_type</span>  application/json;<br><br>    <span class="hljs-attribute">sendfile</span>        <span class="hljs-literal">on</span>;<br>    <br>    <span class="hljs-attribute">keepalive_timeout</span>  <span class="hljs-number">65</span>;<br><br>    <span class="hljs-section">upstream</span> memory-blog &#123;   <br>      <span class="hljs-attribute">server</span> localhost:<span class="hljs-number">4000</span>;<br>    &#125;<br><br>    <span class="hljs-section">upstream</span> memory-docs1 &#123;   <br>      <span class="hljs-attribute">server</span> localhost:<span class="hljs-number">5173</span>;<br>    &#125;<br><br>    <span class="hljs-section">upstream</span> memory-docs2 &#123;   <br>      <span class="hljs-attribute">server</span> localhost:<span class="hljs-number">8080</span>;<br>    &#125;<br>    <br>    <span class="hljs-section">server</span> &#123;<br>        <span class="hljs-attribute">listen</span>       <span class="hljs-number">8887</span>;<br>        <span class="hljs-attribute">server_name</span>  localhost;<br>       <br>        <span class="hljs-section">location</span> / &#123;<br>            <span class="hljs-attribute">proxy_pass</span>  http://memory-blog; <br>        &#125;<br><br>        <span class="hljs-attribute">error_page</span>   <span class="hljs-number">500</span> <span class="hljs-number">502</span> <span class="hljs-number">503</span> <span class="hljs-number">504</span>  /50x.html;<br>        <span class="hljs-section">location</span> = /50x.html &#123;<br>            <span class="hljs-attribute">root</span>   html;<br>        &#125;<br>    &#125;<br><br>    <span class="hljs-section">server</span> &#123;<br>        <span class="hljs-attribute">listen</span>       <span class="hljs-number">8888</span>;<br>        <span class="hljs-attribute">server_name</span>  localhost;<br>        <br>        <span class="hljs-section">location</span> / &#123;<br>            <span class="hljs-attribute">proxy_pass</span>  http://memory-docs1; <br>        &#125;<br><br>        <span class="hljs-attribute">error_page</span>   <span class="hljs-number">500</span> <span class="hljs-number">502</span> <span class="hljs-number">503</span> <span class="hljs-number">504</span>  /50x.html;<br>        <span class="hljs-section">location</span> = /50x.html &#123;<br>            <span class="hljs-attribute">root</span>   html;<br>        &#125;<br>    &#125;<br><br><br>    <span class="hljs-section">server</span> &#123;<br>        <span class="hljs-attribute">listen</span>       <span class="hljs-number">8889</span>;<br>        <span class="hljs-attribute">server_name</span>  localhost;<br>       <br>        <span class="hljs-section">location</span> / &#123;<br>            <span class="hljs-attribute">proxy_pass</span>  http://memory-docs2; <br>        &#125;<br><br>        <span class="hljs-attribute">error_page</span>   <span class="hljs-number">500</span> <span class="hljs-number">502</span> <span class="hljs-number">503</span> <span class="hljs-number">504</span>  /50x.html;<br>        <span class="hljs-section">location</span> = /50x.html &#123;<br>            <span class="hljs-attribute">root</span>   html;<br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="有关配置的详细讲解，在配置文件👆一栏中了解"><a href="#有关配置的详细讲解，在配置文件👆一栏中了解" class="headerlink" title="有关配置的详细讲解，在配置文件👆一栏中了解"></a>有关配置的详细讲解，在配置文件👆一栏中了解</h5></li>
<li><h5 id="修改完配置，我们重新加载配置文件，并启动Nginx服务"><a href="#修改完配置，我们重新加载配置文件，并启动Nginx服务" class="headerlink" title="修改完配置，我们重新加载配置文件，并启动Nginx服务"></a>修改完配置，我们重新加载配置文件，并启动Nginx服务</h5></li>
</ul>
<figure class="highlight ebnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs ebnf"><span class="hljs-attribute">nginx -s reload</span> <br></code></pre></td></tr></table></figure>

<figure class="highlight ebnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs ebnf"><span class="hljs-attribute">nginx</span><br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="分别访问本地8887、8888、8889端口："><a href="#分别访问本地8887、8888、8889端口：" class="headerlink" title="分别访问本地8887、8888、8889端口："></a>分别访问本地8887、8888、8889端口：</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230708100936095.png" alt="image-20230708100936095"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230708100544510.png" alt="image-20230708100544510"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230708100612584.png" alt="image-20230708100612584"></p>
<ul>
<li><h5 id="可以看到，我们开启了Nginx服务，只需访问Nginx给我们开放的端口，就能够访问到对应服务器，获取页面数据"><a href="#可以看到，我们开启了Nginx服务，只需访问Nginx给我们开放的端口，就能够访问到对应服务器，获取页面数据" class="headerlink" title="可以看到，我们开启了Nginx服务，只需访问Nginx给我们开放的端口，就能够访问到对应服务器，获取页面数据"></a>可以看到，我们开启了Nginx服务，只需访问Nginx给我们开放的端口，就能够访问到对应服务器，获取页面数据</h5></li>
<li><h5 id="这是因为Nginx将我们的请求转发给了服务器，而用户是无感知的，这就是Nginx反向代理"><a href="#这是因为Nginx将我们的请求转发给了服务器，而用户是无感知的，这就是Nginx反向代理" class="headerlink" title="这是因为Nginx将我们的请求转发给了服务器，而用户是无感知的，这就是Nginx反向代理"></a>这是因为Nginx将我们的请求转发给了服务器，而用户是无感知的，这就是Nginx反向代理</h5></li>
</ul>
<h2 id="静态网站部署"><a href="#静态网站部署" class="headerlink" title="静态网站部署"></a>静态网站部署</h2><h2 id="HTTPS配置"><a href="#HTTPS配置" class="headerlink" title="HTTPS配置"></a>HTTPS配置</h2><ul>
<li><h5 id="使用-Nginx-配置-HTTPS：安全加密通信"><a href="#使用-Nginx-配置-HTTPS：安全加密通信" class="headerlink" title="使用 Nginx 配置 HTTPS：安全加密通信"></a>使用 Nginx 配置 HTTPS：安全加密通信</h5></li>
</ul>
<h2 id="虚拟主机"><a href="#虚拟主机" class="headerlink" title="虚拟主机"></a>虚拟主机</h2><ul>
<li><h5 id="Nginx-虚拟主机配置：多个网站共享一台服务器"><a href="#Nginx-虚拟主机配置：多个网站共享一台服务器" class="headerlink" title="Nginx 虚拟主机配置：多个网站共享一台服务器"></a>Nginx 虚拟主机配置：多个网站共享一台服务器</h5></li>
</ul>
<h2 id="踩坑经历"><a href="#踩坑经历" class="headerlink" title="踩坑经历"></a>踩坑经历</h2><h3 id="访问Nginx403错误"><a href="#访问Nginx403错误" class="headerlink" title="访问Nginx403错误"></a>访问Nginx403错误</h3><ul>
<li><h5 id="运维排查篇-访问nginx出现403错误-知乎-zhihu-com"><a href="#运维排查篇-访问nginx出现403错误-知乎-zhihu-com" class="headerlink" title="运维排查篇 | 访问nginx出现403错误 - 知乎 (zhihu.com)"></a><a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/381967653">运维排查篇 | 访问nginx出现403错误 - 知乎 (zhihu.com)</a></h5></li>
<li><h5 id="详解Nginx出现403Forbidden的解决办法-第一PHP社区-php1-cn"><a href="#详解Nginx出现403Forbidden的解决办法-第一PHP社区-php1-cn" class="headerlink" title="详解Nginx出现403Forbidden的解决办法 - 第一PHP社区 (php1.cn)"></a><a target="_blank" rel="noopener" href="https://www.php1.cn/detail/XiangJie_Nginx_C_5d37dae4.html">详解Nginx出现403Forbidden的解决办法 - 第一PHP社区 (php1.cn)</a></h5></li>
<li><h5 id="四种解决Nginx出现403-forbidden-报错的方法-baidu-com"><a href="#四种解决Nginx出现403-forbidden-报错的方法-baidu-com" class="headerlink" title="四种解决Nginx出现403 forbidden 报错的方法 (baidu.com)"></a><a target="_blank" rel="noopener" href="https://baijiahao.baidu.com/s?id=1614533633678689239&wfr=spider&for=pc">四种解决Nginx出现403 forbidden 报错的方法 (baidu.com)</a></h5></li>
<li><h5 id="先是看了很多解决办法（以上），虽然没有解决，但丰富了我对Nginx配置的理解"><a href="#先是看了很多解决办法（以上），虽然没有解决，但丰富了我对Nginx配置的理解" class="headerlink" title="先是看了很多解决办法（以上），虽然没有解决，但丰富了我对Nginx配置的理解"></a>先是看了很多解决办法（以上），虽然没有解决，但丰富了我对Nginx配置的理解</h5></li>
<li><h5 id="然后我想到看错误日志，但查看配置发现默认没开启，那就开启错误日志："><a href="#然后我想到看错误日志，但查看配置发现默认没开启，那就开启错误日志：" class="headerlink" title="然后我想到看错误日志，但查看配置发现默认没开启，那就开启错误日志："></a>然后我想到看错误日志，但查看配置发现默认没开启，那就开启错误日志：</h5></li>
<li><h5 id="错误日志路径："><a href="#错误日志路径：" class="headerlink" title="错误日志路径："></a>错误日志路径：</h5></li>
</ul>
<img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230622154436897.png" style="zoom:67%;" />

<ul>
<li><h5 id="开启错误日志："><a href="#开启错误日志：" class="headerlink" title="开启错误日志："></a>开启错误日志：</h5></li>
</ul>
<img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230622154707468.png" alt="image-20230622154707468" style="zoom: 80%;" />

<ul>
<li><h5 id="查看错误日志，发现问题所在："><a href="#查看错误日志，发现问题所在：" class="headerlink" title="查看错误日志，发现问题所在："></a>查看错误日志，发现问题所在：</h5></li>
</ul>
<img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230622154920109.png" alt="image-20230622154920109" style="zoom:150%;" />

<ul>
<li><h5 id="接着看这个解决思路：-67条消息-报错：directory-index-of-“xxx“-is-forbidden-directory-index-of-is-forbidden-AI人工智能与大数据的博客-CSDN博客"><a href="#接着看这个解决思路：-67条消息-报错：directory-index-of-“xxx“-is-forbidden-directory-index-of-is-forbidden-AI人工智能与大数据的博客-CSDN博客" class="headerlink" title="接着看这个解决思路：(67条消息) 报错：directory index of “xxx“ is forbidden_directory index of is forbidden_AI人工智能与大数据的博客-CSDN博客"></a>接着看这个解决思路：<a target="_blank" rel="noopener" href="https://blog.csdn.net/guanxs/article/details/107901101">(67条消息) 报错：directory index of “xxx“ is forbidden_directory index of is forbidden_AI人工智能与大数据的博客-CSDN博客</a></h5></li>
<li><h5 id="添加这行配置："><a href="#添加这行配置：" class="headerlink" title="添加这行配置："></a>添加这行配置：</h5></li>
</ul>
<img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230622155144376.png" alt="image-20230622155144376" style="zoom: 80%;" />

<ul>
<li><h5 id="然后访问Nginx（记得nginx-s-reload），访问成功，大功告成"><a href="#然后访问Nginx（记得nginx-s-reload），访问成功，大功告成" class="headerlink" title="然后访问Nginx（记得nginx -s reload），访问成功，大功告成"></a>然后访问Nginx（记得nginx -s reload），访问成功，大功告成</h5></li>
<li><h5 id="这就是访问Nginx发生403错误的具体解决办法了，很有收获"><a href="#这就是访问Nginx发生403错误的具体解决办法了，很有收获" class="headerlink" title="这就是访问Nginx发生403错误的具体解决办法了，很有收获"></a>这就是访问Nginx发生403错误的具体解决办法了，很有收获</h5></li>
</ul>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1>
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/memory_blog/categories/Nginx/" class="category-chain-item">Nginx</a>
  
  
    <span>></span>
    
  <a href="/memory_blog/categories/Nginx/Linux/" class="category-chain-item">Linux</a>
  
  
    <span>></span>
    
  <a href="/memory_blog/categories/Nginx/Linux/Node-js/" class="category-chain-item">Node.js</a>
  
  
    <span>></span>
    
  <a href="/memory_blog/categories/Nginx/Linux/Node-js/%E7%BB%8F%E9%AA%8C/" class="category-chain-item">经验</a>
  
  

  

  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/memory_blog/tags/%E7%BB%8F%E9%AA%8C/">#经验</a>
      
        <a href="/memory_blog/tags/Linux/">#Linux</a>
      
        <a href="/memory_blog/tags/Nginx/">#Nginx</a>
      
        <a href="/memory_blog/tags/Node-js/">#Node.js</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Nginx 入门指南：理解、配置和优化</div>
      <div>https://test.atomgit.net/memory_blog/2023/06/22/Nginx 入门指南：理解、配置和优化/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Memory</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年6月22日</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>更新于</div>
          <div>2024年6月21日</div>
        </div>
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/memory_blog/2023/06/22/AI%20%E5%AE%9E%E8%B7%B5%E4%B8%AD%E7%9A%84%E6%B4%9E%E8%A7%81%EF%BC%9A%E6%88%91%E7%9A%84%20AI%20%E4%B9%8B%E6%97%85/" title="AI实践中的洞见：我的AI之旅">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">AI实践中的洞见：我的AI之旅</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/memory_blog/2023/06/20/Typora%E6%93%8D%E4%BD%9C%E6%8A%80%E5%B7%A7/" title="美轮美奂的文档艺术：Typora的使用技巧和实践">
                        <span class="hidden-mobile">美轮美奂的文档艺术：Typora的使用技巧和实践</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments">
      

    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.fluid-dev.com/docs/guide/" target="_blank" rel="nofollow noopener"> <span>Memory | 个人文档站点</span> </a>
<i class="iconfont icon-love"></i> <a href="https://hexo.fluid-dev.com/docs/guide/" target="_blank" rel="nofollow noopener"> <span>配置指南 | Hexo Fluid 用户手册</span> </a>   
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="leancloud-site-pv-container" style="display: none">
        总访问量 
        <span id="leancloud-site-pv"></span>
         次
      </span>
    
    
      <span id="leancloud-site-uv-container" style="display: none">
        总访客数 
        <span id="leancloud-site-uv"></span>
         人
      </span>
    
    

  
</div>

  
  
    <!-- 备案信息 ICP for China -->
    <div class="beian">
  <span>
    <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
      京ICP证123456号
    </a>
  </span>
  
    
      <span>
        <a
          href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=12345678"
          rel="nofollow noopener"
          class="beian-police"
          target="_blank"
        >
          
            <span style="visibility: hidden; width: 0">|</span>
            <img src="/memory_blog/img/police_beian.png" alt="police-icon"/>
          
          <span>京公网安备12345678号</span>
        </a>
      </span>
    
  
</div>

  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/memory_blog/js/events.js" ></script>
<script  src="/memory_blog/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>







  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/memory_blog/js/local-search.js" ></script>

  <script defer src="/memory_blog/js/leancloud.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/memory_blog/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
